import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Array_Hoppers_Chanllenge {

	int[] array;
	String out;

	public Array_Hoppers_Chanllenge(String args) {
		this.array = readFile(args);
		this.out = minHop(array);
	}

	/**
	 * Find the minHop to print out.
	 * 
	 * @param input		the int array
	 * @return 			1 possible output string
	 */
	public String minHop(int[] input) {
		int len = input.length;
		int[] hoppers = new int[len];
		String to_return = "";
		if (len == 0 || input[0] == 0)
			to_return = "failure";
		else {
			hoppers[0] = 0;
			for (int i = 1; i < len; i++) {
				hoppers[i] = Integer.MAX_VALUE;
				for (int j = 0; j < i; j++) {
					if (i <= j + input[j] && hoppers[j] != Integer.MAX_VALUE) {
						hoppers[i] = hoppers[j] + 1;
						break;
					}
				}
			}
		}
		// Change the steps to the output string
		if (hoppers[len - 1] == Integer.MAX_VALUE || hoppers[len - 1] == 0)
			to_return = "failure";
		else {
			to_return = String.valueOf(len - 1) + ", out";
			int flag = hoppers[len - 1];
			for (int i = len - 1; i >= 0; i--) {
				int temp = hoppers[i];
				if (temp != flag) {
					to_return = String.valueOf(i) + ", " + to_return;
					flag = temp;
				}
			}
		}
		return to_return;

	}

	/**
	 * Get the input data from the file, The data form is 3 4 5 6 which will
	 * return [3,4,5,6]
	 * 
	 * @param args
	 *            the file name
	 * @return an integer array
	 */
	public int[] readFile(String args) {
		// Get the input File line by line
		int[] to_return = null;
		try {
			FileReader fin = new FileReader(args);
			BufferedReader in = new BufferedReader(fin);
			String line;
			ArrayList<Integer> array = new ArrayList<Integer>();
			while ((line = in.readLine()) != null) {
				try {
					array.add(Integer.valueOf(line));
				} catch (NumberFormatException e) {
					System.err.println("Error Input");
				}

			}
			to_return = new int[array.size()];
			for (int i = 0; i < array.size(); i++) {
				to_return[i] = array.get(i);
			}
			in.close();
			fin.close();

		} catch (FileNotFoundException e) {
			System.err.println("Cannot find the file.");
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println("IO exception");
			e.printStackTrace();
		}
		return to_return;
	}

	public static void main(String[] args) {
		System.out.println("Please input your file location");
		Scanner in = new Scanner(System.in);
		String fileloc = in.nextLine();
		in.close();
//		Array_Hoppers_Chanllenge test = new Array_Hoppers_Chanllenge(
//				"/Users/stflaptop/Desktop/1.txt");
		Array_Hoppers_Chanllenge test = new Array_Hoppers_Chanllenge(fileloc);

		int[] temp = test.array;
		for (int i = 0; i < temp.length; i++) {
			System.out.print(temp[i] + ", ");
		}
		System.out.println("\n" + test.out);

	}

}
